<?php

class SettingController extends Controller
{
    public function init() {

        parent::init();
        $this->R->module = "配置操作";
    }
	public function actionIndex()
	{
        $list = Config::model()->findAll();
        $arr = array();
        foreach($list as $v)
        {
            $arr[$v->Key] = $v->Value;
        }
        $form = json_encode($arr);
        $this->render('index',array('form'=>$form));
	}
    public function actionSave() {
        if(isset($_POST['title']))
        {
            $form = new SettingForm();
            $form->attributes = $_POST;
            if($form->validate())
            {
                $this->R->action = "设置配置";
                foreach($_POST as $k=>$v)
                {
                    Config::model()->updateByPk($k,array('Value'=>$v));
                }
                $this->R->success = true;
            }else
                 $this->R->success = false;
            $this->R->flush();
        }
    }


	// Uncomment the following methods and override them if needed
	/*
	public function filters()
	{
		// return the filter configuration for this controller, e.g.:
		return array(
			'inlineFilterName',
			array(
				'class'=>'path.to.FilterClass',
				'propertyName'=>'propertyValue',
			),
		);
	}

	public function actions()
	{
		// return external action classes, e.g.:
		return array(
			'action1'=>'path.to.ActionClass',
			'action2'=>array(
				'class'=>'path.to.AnotherActionClass',
				'propertyName'=>'propertyValue',
			),
		);
	}
	*/
}